<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="keywords" content="">
  <meta name="description" content="">
  <title>加签</title>
  <link href="/static/css/bootstrap.min.css" rel="stylesheet"/>
  <link rel="stylesheet" href="/static/include/css/style.css">
  <style>
    #msgContent{
      display: none;
    }
  </style>
</head>
<body class="white-bg" style="height: 95%">

<div>
  <table class="form-table">
    <tr>
      <th>
        <span class="required">*</span><span>加签人：</span>
      </th>
      <td>
        <span id="username"></span>
        <a class="btn btn-primary btn-sm" onclick="checkUser()"><i class="fa fa-search"></i> 选择用户</a>
      </td>
    </tr>
  </table>
</div>


<script src="/static/include/js/footer.js"></script>
<script>
  var userRows = []
  $(function () {
  })
  function checkUser() {
    var url = '/pages/bpm/agent/userTable';
    var options = {
      title: '选择转交人',
      url: url,
      callBack: doSubmitUser
    };
    var userIds = []
    userRows.forEach(function (user) {
      userIds.push(user.id)
    })
    $.modal.openOptionsInitData(options, userIds);
  }

  function doSubmitUser(index, layero) {
    var iframeWin = window[layero.find('iframe')[0]['name']];
    var rows = iframeWin.$('#bootstrap-table').bootstrapTable('getSelections');
    userRows = []
    rows.forEach(function (row) {
      userRows.push({
        name: row.username,
        id: row.user_id,
        type: 'user'
      })
    })
    formatSr()
    layer.close(index);
  }

  function formatSr() {
    userRows.forEach(function (user) {
      $("#username").append('<span class="user-btn btn btn-default btn-xs" style="margin-right: 5px;" data-id="\''+user.id+'\'">' +
        '' + user.name +
        '<a href="javascript:void(0)" class="btn btn-link btn-xs" onclick="removeUser(this,\''+user.id+'\')">×</a>' +
        '</span>')
    })

  }

  function removeUser(obj,id) {
    $(obj).parent().remove()
    userRows.forEach(function (user,index) {
      if (user.id == id){
        userRows.splice(index,1)
      }
    })
  }

  function submitHandler() {
    if (!userRows.length){
      $.modal.msgWarning('请选择抄送人！')
      return false
    }
    parent.window.nowButton.opinion =  $('#opinion').val()
    parent.window.nowButton.configPage = ''
    var msgType = []
    $('input[name="msgType"]:checked').each(function(){
      msgType.push($(this).val());
    });
    var data = {
      users: userRows
    }
    parent.window.bpmParams = Object.assign({}, parent.window.bpmParams, {extendConf: data})
    parent.window.postFn(parent.window.nowButton)
  }
</script>
</body>
</html>
